package org.micro.frame.es;

import org.elasticsearch.action.get.GetRequest;
import org.elasticsearch.client.RestHighLevelClient;
import org.elasticsearch.common.Strings;
import org.elasticsearch.search.fetch.subphase.FetchSourceContext;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
public class ElasticsearchController {

    @Autowired
    private RestHighLevelClient restHighLevelClient;

    @RequestMapping("/test")
    public Object test() throws Exception {
        String[] includes = new String[]{"message", "*Date"};
        GetRequest request = new GetRequest("posts", "doc", "1");
        request.fetchSourceContext(new FetchSourceContext(true, includes, Strings.EMPTY_ARRAY));

        return restHighLevelClient.get(request);
    }

}